package com.wanxi.education.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanxi.education.mapper.AgencyMapper;
import com.wanxi.education.model.pojo.Agency;
import com.wanxi.education.model.vo.agency.*;
import com.wanxi.education.service.AgencyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: WangRui
 * @Description:
 * @Date: Created in 2021/9/24 0024
 * @Version: 1.0
 */
@Service
public class AgencyServiceImpl implements AgencyService {

    @Autowired
    private AgencyMapper agencyMapper;

    @Override
    public Long add(AgencyAddVo agencyAddVo) {
        Agency agency = new Agency();
        BeanUtils.copyProperties(agencyAddVo,agency);
        agencyMapper.add(agency);
        return agency.getId();
    }

    @Override
    public AgencyVo findById(Long id) {
        Agency agency = agencyMapper.findById(id);
        AgencyVo agencyVo = new AgencyVo();
        BeanUtils.copyProperties(agency,agencyVo);
        return agencyVo;
    }

    @Override
    public PageInfo<AgencyVo> findPage(AgencyPageVo agencyPageVo) {
        PageHelper.startPage(agencyPageVo.getPageNum(),agencyPageVo.getPageSize());
        Agency agency = new Agency();
        BeanUtils.copyProperties(agencyPageVo,agency);
        List<AgencyVo> list = agencyMapper.findAll(agency);
        PageInfo<AgencyVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void updateById(AgencyUpdateVo agencyUpdateVo) {
        Agency agency = new Agency();
        BeanUtils.copyProperties(agencyUpdateVo,agency);
        agency.setUpdateTime(new Date());
        agencyMapper.updateById(agency);
    }

    @Override
    public void deleteById(Long id) {
        Agency agency = new Agency();
        agency.setId(id);
        agency.setUpdateTime(new Date());
        agency.setDeleteStatus((byte) 1);
        agencyMapper.deleteById(agency);
    }

    @Override
    public List<AgencyVo> findAll(AgencyVo agencyVo) {
        Agency agency = new Agency();
        BeanUtils.copyProperties(agencyVo,agency);
        List<AgencyVo> list = agencyMapper.findAll(agency);
        return list;
    }

    @Override
    public List<AgencyInfoVo> findInfoAll() {
        List<AgencyInfoVo> list = agencyMapper.findInfoAll();
        return list;
    }

    @Override
    public List<AgencyInfoVo> findInfoAllNotBinding() {
        List<AgencyInfoVo> list = agencyMapper.findInfoAllNotBinding();
        return list;
    }
}
